package com.clean.cleantotal.compores

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import com.clean.cleantotal.R
import com.clean.cleantotal.base.BaseFragment
import com.clean.cleantotal.bean.DataUtils
import com.clean.cleantotal.bean.FunType
import com.clean.cleantotal.bean.HomeBean
import com.clean.cleantotal.databinding.FragmentToolsBinding
import com.clean.cleantotal.compores.app.ScanAppActivity
import com.clean.cleantotal.compores.compress.CompressActivity
import com.clean.cleantotal.compores.empty.EmptyActivity
import com.clean.cleantotal.utils.Utils
import com.drake.brv.utils.linear
import com.drake.brv.utils.setup

/**
 * 工具
 */
class ToolsFragment : BaseFragment<FragmentToolsBinding>() {
    override fun getViewBinding(
        inflater: LayoutInflater, container: ViewGroup?
    ): FragmentToolsBinding {
        return FragmentToolsBinding.inflate(layoutInflater, container, false)
    }

    override fun initView() {
        mBinding.recyclerView.linear().setup {
            addType<HomeBean> { R.layout.item_tools_layout }
            onClick(R.id.toolsLayout) {
                val model = getModel<HomeBean>()
                when (model.funType) {
                    FunType.EMPTY -> {
                        Utils.requestPr(context) {
                            openActivity(EmptyActivity::class.java)
                        }
                    }

                    FunType.COMPRESS -> {
                        Utils.requestPr(context) {
                            openActivity(CompressActivity::class.java)
                        }
                    }

                    FunType.TIK, FunType.INS, FunType.TEL, FunType.WHATSAPP -> {
                        Utils.requestPr(context) {
                            openActivity(ScanAppActivity::class.java, Bundle().apply {
                                putSerializable("funType", model.funType)
                                putString("title", model.title)
                            })
                        }
                    }

                    else -> {

                    }
                }
            }
        }.models = DataUtils.getToolsList()
    }

    override fun initData(savedInstanceState: Bundle?) {
    }

}